package cn.schoolwow.util.module.crypto.cipher.rsa.flow;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

import java.security.KeyPair;
import java.security.KeyPairGenerator;

public class GenerateKeyPairFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        int keyLength = flowContext.checkData("keyLength", int.class);

        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
        keyGen.initialize(keyLength);
        KeyPair keyPair = keyGen.generateKeyPair();
        flowContext.putInstanceData(keyPair, KeyPair.class);
    }

    @Override
    public String name() {
        return "生成密钥对";
    }
}
